import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'

import UnoCSS from 'unocss/vite'

const publicDir = resolve('resources')
const envDir = resolve('build')

/** @type { import('vite').UserConfig } */
const config = {
  publicDir,
  envDir,
  envPrefix: 'VITE_ELECTRON',
  base: './', // "/" 表示相对于域名的根路径， "./" 表示资源所在文件夹的相对路径
  plugins: [
    vue(),
    AutoImport({
      resolvers: [AntDesignVueResolver()],
      imports: ['vue', 'vue-router']
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false // css in js
        })
      ]
    }),
    VueSetupExtend(),
    UnoCSS()
  ],
  build: {
    terserOptions: {
      compress: {
        drop_console: true
      }
    },
    minify: 'terser'
    // 小于以下值得的图片会自动转换为 base64 图片
    // assetsInlineLimit: 4096,
    // 是否将 import() 分割后的模块的 css 全部打包到一个文件中
    // cssCodeSplit: false
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, './src/renderer/src')
    }
  }
  // server: {
  //   proxy: {
  //     '': {
  //       target: 'https://www.axshare.com',
  //       changeOrigin: true,
  //       rewrite: (path) => path.replace(/^\/api/, '')
  //     }
  //   }
  // },
}

export default config
